%% main code for Ramsey and private eqm

clear all;
clc;
close all;
warning off;

irun_Ramsey=2; % 1, Ramsey; 2 private with 1/theta*pi22

isave  = 1;


iuse_taux=2; % 0, use taux=0; 1 taux=ss; 2 taux=1/(theta*pi22), for private eqm


T1_frac = 0.5; % T1_frac*log(T1),starting point for T1 during the transition, fraction of Tss1
T2_frac = 1;

use_shock = 1; % 1 use alpha shock, 2 use dshock
n     =  2; % number of countries
ns      =  1;
beta   = 1/(1+0.1);     % discount factor, 0.06
theta  = 2;  % theta=2
sigmaH = 1.00001; %bench2.5
sigmaF = 1.00001;

iuse_delta=0;
if (iuse_delta==1)
    delta  = 0.05;
    gL     = 1/(1-delta)-1;
else
    gL      = 0.02;
    delta  = 1-1/(1+gL);
end

dbar   = 1.1;


rhoa   = 0.95;
std_ea = 0.001;

rhod   = 0.95;
std_ed = 0.1;

%L = ones(n,1);
L =[1;1];
betas = ones(ns,1)/ns;

rho   = beta*(1-delta);
rbest = delta/(theta*(1-beta*(1-delta))+delta);

ncountries=n;
nsectors = ns;


alpha = [1;0.9];


%% run steady state
main_notForDynare_solveSS;


%% dynare code

% either Ramsey or private with 1/(theta*pi22)

%% dynare perfect foresight

rpara(1) = ncountries;
rpara(2) = nsectors;
rpara(3) = beta;
rpara(4) = theta;
rpara(5) = sigmaH;
rpara(6) = gL;
rpara(7) = dbar;
rpara(8) = delta;
rpara(9) = L(1);
rpara(10) = L(2);
rpara(11) = alpha(1);
rpara(12) = alpha(2);
rpara(13) = rhoa;
rpara(14) = std_ea;
rpara(15) = extax_ss;
rpara(16) = lrss;
rpara(17) = log(T1_frac*Tss(1));
rpara(18) = log(T2_frac*Tss(2));


rpara(19) = xss(1);
rpara(20) = xss(2);
rpara(21) = Pss(2);
rpara(22) = wss(1);
rpara(23) = wss(2);
rpara(24) = rss;
rpara(25) = pi_ss(1,2);
rpara(26) = pi_ss(2,1);
rpara(27) = riskfree_ss;
rpara(28) = rmul_ss;
rpara(29) = sigmaF;

mpara = rpara;
save setpara_ramsey mpara

if (irun_Ramsey==1)
    dynare Ramsey_1s2c_perfect2 noclearall;
    if (isave==1)
        cfname = ['./results_all/Ramsey_sH',num2str(floor(sigmaH*100)/100),'_sF',num2str(floor(sigmaF*100)/100),'.mat'];
        copyfile('Ramsey_1s2c_perfect2_results.mat', cfname)
    end

else
    % private equilibrium
    % dynare private_1s2c_perfect2 noclearall;
    if (iuse_taux==0)
        % taux=0
        dynare private_1s2c_perfect2 noclearall;
    else
        % taux=1/(theta*pi22) endogenously
        dynare private_1s2c_perfect2_varyTaux noclearall;
    end

    if (isave==1)
        cfname = ['./results_all/private_sH',num2str(floor(sigmaH*100)/100),'_sF',num2str(floor(sigmaF*100)/100),'.mat'];
        copyfile('private_1s2c_perfect2_varyTaux_results.mat', cfname)
    end
end
